﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.t105Menu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void t105_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            t105Mgr mgr = new t105Mgr();
            e.Total = int.Parse(mgr.GetRecordCount_t105(e.Parameters[t105_Filter.ParamPrefix]));
            IList<t105> list = mgr.FindAllByPage_t105(e.Start.ToString(), e.Limit.ToString(), e.Parameters[t105_Filter.ParamPrefix]);
            t105_MainStore.DataSource = list;
            t105_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            t105Mgr mgr = new t105Mgr();
            RowSelectionModel sm = t105_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                t105 _t105 = new t105();
                _t105.t105_00 = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_t105(_t105))
                {
                    log.Debug("t105中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            t105_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            t105Mgr mgr = new t105Mgr();
            t105 _t105 = new t105();
            if (Hid.Text.Length > 0)
                _t105 = mgr.FindById_t105(int.Parse(Hid.Text));
            
			_t105.t105_01 = Txtt105_01.Text.Trim();
			_t105.t105_02 = Txtt105_02.Text.Trim();
			_t105.t105_03 = Txtt105_03.Text.Trim();
			_t105.t105_04 = Txtt105_04.Text.Trim();
			_t105.t105_70 = Txtt105_70.Text.Trim();
			_t105.t105_05 = Txtt105_05.Text.Trim();
			_t105.t105_06 = Txtt105_06.Text.Trim();
			_t105.t105_07 = Txtt105_07.Text.Trim();
			_t105.t105_08 = Txtt105_08.Text.Trim();
			_t105.t105_09 = Txtt105_09.Text.Trim();
			_t105.t105_10 = Txtt105_10.Text.Trim();
			_t105.t105_11 = Txtt105_11.Text.Trim();
			_t105.t105_12 = Txtt105_12.Text.Trim();
			_t105.t105_71 = Txtt105_71.Text.Trim();
			_t105.t105_13 = Txtt105_13.Text.Trim();
			_t105.t105_14 = Txtt105_14.Text.Trim();
			_t105.t105_15 = Txtt105_15.Text.Trim();
			_t105.t105_16 = Txtt105_16.Text.Trim();
			_t105.t105_17 = Txtt105_17.Text.Trim();
			_t105.t105_18 = Txtt105_18.Text.Trim();
			_t105.collection_time = Txtcollection_time.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_t105(_t105);
            else
                isok = mgr.Add_t105(_t105);
            if (isok)
            {
                t105_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("t105中执行了保存（插入或修改），并成功");
                t105_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}